def isPrime(v):
    if v == 1: return False
    test = True
    k = v - 1
    while k > 1:
        if not v % k:
            test = False
            break
        k -= 1
    return test

n = input()
if 1000 > n > 10000:
    print(0)
    exit()
z = []
for i in range(len(n)):
    for k in range(i + 1, len(n) + 1):
        v = int(n[i:k])
        if isPrime(v):
            z += [v]
print(max(z) if z else 0)